/* Copyright (c) 2004-2008, Andriy Nikolov
 * All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.processmining.email;

import javax.swing.table.*;

/**
 * <p>The table model class to show the sociogram matrix in a table</p>
 *
 * @author Andriy Nikolov
 * @version 1.0
 */
public class SociogramTableModel
    extends AbstractTableModel {
  Sociogram sociogram;

  public SociogramTableModel() {
  }

  public SociogramTableModel(Sociogram sociogram) {
    this.sociogram = sociogram;
  }

  public void setSociogram(Sociogram sociogram) {
    this.sociogram = sociogram;
  }
  public int getRowCount() {
    return sociogram.getEmployeesList().size();
  }

  public int getColumnCount() {
    return sociogram.getEmployeesList().size()+1;
  }

  public String getColumnName(int col) {
    EMailRecipient tmp;
    if(col==0) {
      return " ";
    } else {
      tmp = (EMailRecipient)sociogram.getEmployeesList().get(col-1);
      return tmp.getName();
    }
  }

  public Class getColumnClass(int c) {
    switch(c) {
    case 0:
      return new String().getClass();
    default:
      return new Double(0).getClass();
    }
  }

  public Object getValueAt(int row, int col) {
    EMailRecipient tmp;
    if (col == 0) {
      tmp = (EMailRecipient) sociogram.getEmployeesList().get(row);
      return tmp.getName();
    }
    else {
      return new Double(sociogram.getWeight(row, col - 1));
    }
  }
}
